﻿@model Profile

<script type="text/javascript" src="~/js/shared/fileUploader.min.js"></script>

<div class="container">

    <h1 class="display-4">Profile</h1>
    <hr />

    <div class="row">
        <div class="col text-center">
            <img id="avatar" src="@($"{OssService.GetAvatar()}?{new Random().Next().ToString()}")" />
        </div>
    </div>

    <div class="row mb-3">
        <div class="col text-center">
            <button id="uploading" class="btn btn-primary" onclick="upload()">Upload Avatar</button>
            <input id="fileSelector" type="file" onchange="uploadAvatar()" hidden />
            @if (!string.IsNullOrEmpty(Model.AdminPassword))
            {
                @await Component.InvokeAsync("FormLink", new FormLink()
                {
                    Text = "Delete Password",
                    ClassName = "btn btn-danger",
                    Warning = "Confirm deletion?",
                    Href = "/Admin/Profile/ResetPassword"
                })
            }
        </div>
    </div>

    <div>
        <form asp-controller="Profile" asp-action="Index" method="post">

            <div class="inputRow">
                <label asp-for="Name"></label>*
                <input asp-for="Name" type="text" autocomplete="off" class="form-control" />
                <span asp-validation-for="Name" class="text-danger"></span>
            </div>

            <div class="inputRow">
                <label asp-for="Info"></label>*
                <input asp-for="Info" type="text" autocomplete="off" class="form-control" />
                <span asp-validation-for="Info" class="text-danger"></span>
            </div>

            <div class="inputRow">
                <label asp-for="QQ"></label>*
                <input asp-for="QQ" type="text" autocomplete="off" class="form-control" />
                <span asp-validation-for="QQ" class="text-danger"></span>
            </div>

            <div class="inputRow">
                <label asp-for="Email"></label>*
                <input asp-for="Email" type="text" autocomplete="off" class="form-control" />
                <span asp-validation-for="Email" class="text-danger"></span>
            </div>

            <div class="inputRow">
                <label asp-for="ICP"></label>*
                <input asp-for="ICP" type="text" autocomplete="off" class="form-control" />
                <span asp-validation-for="ICP" class="text-danger"></span>
            </div>

            @if (string.IsNullOrEmpty(Model.AdminPassword))
            {
                <div class="inputRow">
                    <label asp-for="AdminPassword"></label>*
                    <input asp-for="AdminPassword" type="text" autocomplete="off" class="form-control" />
                    <span asp-validation-for="AdminPassword" class="text-danger"></span>
                </div>
            }
            else
            {
                <input asp-for="AdminPassword" type="hidden" />
            }

            <input id="submit-profile" type="submit" value="Apply" class="btn btn-success" />

        </form>

    </div>

    <div class="inputRow mt-5">
        @{
            var formLink = new FormLink()
            {
                Text = "Delete",
                ClassName = "btn btn-danger",
                Warning = "Confirm deletion?"
            };
        }
        <hr />
        <h1 class="display-4">What's new</h1>
        <form asp-controller="Profile" asp-action="AddFooterLink" asp-route-type="WhatsNew" method="post" class="input-group">
            <input type="text" name="Title" placeholder="Title" class="form-control" autocomplete="off" />
            <input type="text" name="Link" placeholder="Link" class="form-control" autocomplete="off" />
            <div class="input-group-append">
                <input class="btn btn-outline-success" type="submit" value="Add Link" />
            </div>
        </form>
        <hr />
        @foreach (var item in Model.WhatsNew)
        {
            <div class="input-group">
                <input type="text" placeholder="Title" class="form-control" value="@item.Title" disabled />
                <input type="text" placeholder="Link" class="form-control" value="@item.Link" disabled />
                <div class="input-group-append">
                    @{
                        formLink.Href = "/Admin/Profile/DeleteFooterLink?type=WhatsNew";
                        formLink.Paras = new Dictionary<string, string>()
                        {
                            {"id", item.Id }
                        };
                    }
                    @await Component.InvokeAsync("FormLink", formLink)
                </div>
            </div>
            <br />
        }
    </div>

    <div class="inputRow">
        <h1 class="display-4">FriendLinks</h1>
        <form asp-controller="Profile" asp-action="AddFooterLink" asp-route-type="FriendLinks" method="post" class="input-group">
            <input type="text" name="Title" placeholder="Title" class="form-control" autocomplete="off" />
            <input type="text" name="Link" placeholder="Link" class="form-control" autocomplete="off" />
            <div class="input-group-append">
                <input class="btn btn-outline-success" type="submit" value="Add Link" />
            </div>
        </form>
        <hr />
        @foreach (var item in Model.FriendLinks)
        {
            <div class="input-group">
                <input type="text" placeholder="Title" class="form-control" value="@item.Title" disabled />
                <input type="text" placeholder="Link" class="form-control" value="@item.Link" disabled />
                <div class="input-group-append">
                    @{
                        formLink.Href = "/Admin/Profile/DeleteFooterLink?type=FriendLinks";
                        formLink.Paras = new Dictionary<string, string>()
                        {
                            {"id", item.Id }
                        };
                    }
                    @await Component.InvokeAsync("FormLink", formLink)
                </div>
            </div>
            <br />
        }
    </div>

    <div class="inputRow">
        <h1 class="display-4">About</h1>
        <form asp-controller="Profile" asp-action="AddFooterLink" asp-route-type="About" method="post" class="input-group">
            <input type="text" name="Title" placeholder="Title" class="form-control" autocomplete="off" />
            <input type="text" name="Link" placeholder="Link" class="form-control" autocomplete="off" />
            <div class="input-group-append">
                <input class="btn btn-outline-success" type="submit" value="Add Link" />
            </div>
        </form>
        <hr />
        @foreach (var item in Model.About)
        {
            <div class="input-group">
                <input type="text" placeholder="Title" class="form-control" value="@item.Title" disabled />
                <input type="text" placeholder="Link" class="form-control" value="@item.Link" disabled />
                <div class="input-group-append">
                    @{
                        formLink.Href = "/Admin/Profile/DeleteFooterLink?type=About";
                        formLink.Paras = new Dictionary<string, string>()
                        {
                            {"id", item.Id }
                        };
                    }
                    @await Component.InvokeAsync("FormLink", formLink)
                </div>
            </div>
            <br />
        }
    </div>

    <div class="inputRow">
        <h1 class="display-4">Others</h1>
        <form asp-controller="Profile" asp-action="AddFooterLink" asp-route-type="Others" method="post" class="input-group">
            <input type="text" name="Title" placeholder="Title" class="form-control" autocomplete="off" />
            <input type="text" name="Link" placeholder="Link" class="form-control" autocomplete="off" />
            <div class="input-group-append">
                <input class="btn btn-outline-success" type="submit" value="Add Link" />
            </div>
        </form>
        <hr />
        @foreach (var item in Model.Others)
        {
            <div class="input-group">
                <input type="text" placeholder="Title" class="form-control" value="@item.Title" disabled />
                <input type="text" placeholder="Link" class="form-control" value="@item.Link" disabled />
                <div class="input-group-append">
                    @{
                        formLink.Href = "/Admin/Profile/DeleteFooterLink?type=Others";
                        formLink.Paras = new Dictionary<string, string>()
                        {
                            {"id", item.Id }
                        };
                    }
                    @await Component.InvokeAsync("FormLink", formLink)
                </div>
            </div>
            <br />
        }
    </div>

</div>